package com.ruoyi.sys.tpackage.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.sys.tpackage.domain.TPackage;
import com.ruoyi.sys.tpackage.service.ITPackageService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 套餐信息管理Controller
 * 
 * @author hyl
 * @date 2025-06-07
 */
@RestController
@RequestMapping("/tpackage/tpackage")
public class TPackageController extends BaseController
{
    @Autowired
    private ITPackageService tPackageService;

    /**
     * 查询套餐信息管理列表
     */
    @PreAuthorize("@ss.hasPermi('tpackage:tpackage:list')")
    @GetMapping("/list")
    public TableDataInfo list(TPackage tPackage)
    {
        startPage();
        List<TPackage> list = tPackageService.selectTPackageList(tPackage);
        return getDataTable(list);
    }

    /**
     * 导出套餐信息管理列表
     */
    @PreAuthorize("@ss.hasPermi('tpackage:tpackage:export')")
    @Log(title = "套餐信息管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TPackage tPackage)
    {
        List<TPackage> list = tPackageService.selectTPackageList(tPackage);
        ExcelUtil<TPackage> util = new ExcelUtil<TPackage>(TPackage.class);
        util.exportExcel(response, list, "套餐信息管理数据");
    }

    /**
     * 获取套餐信息管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('tpackage:tpackage:query')")
    @GetMapping(value = "/{packId}")
    public AjaxResult getInfo(@PathVariable("packId") Long packId)
    {
        return success(tPackageService.selectTPackageByPackId(packId));
    }

    /**
     * 新增套餐信息管理
     */
    @PreAuthorize("@ss.hasPermi('tpackage:tpackage:add')")
    @Log(title = "套餐信息管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TPackage tPackage)
    {
        return toAjax(tPackageService.insertTPackage(tPackage));
    }

    /**
     * 修改套餐信息管理
     */
    @PreAuthorize("@ss.hasPermi('tpackage:tpackage:edit')")
    @Log(title = "套餐信息管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TPackage tPackage)
    {
        return toAjax(tPackageService.updateTPackage(tPackage));
    }

    /**
     * 删除套餐信息管理
     */
    @PreAuthorize("@ss.hasPermi('tpackage:tpackage:remove')")
    @Log(title = "套餐信息管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{packIds}")
    public AjaxResult remove(@PathVariable Long[] packIds)
    {
        return toAjax(tPackageService.deleteTPackageByPackIds(packIds));
    }
}
